#include <myhead.h>
typedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;      
typedef struct sockaddr_un addr_un_t;
int main(int argc, const char *argv[])
{
	//1.创建套接字
	int server = socket(AF_INET,SOCK_STREAM,0);
	//准备一个tcp用的结构体
	addr_in_t server_addr={0};
	server_addr.sin_family=AF_INET;
	server_addr.sin_port=htons(12345);
	server_addr.sin_addr.s_addr=inet_addr("0.0.0.0");
	//2.绑定本机
	if(bind(server,(addr_t*)&server_addr,sizeof(server_addr))==-1)
	{
		perror("bind");
		return 1;
	}
	//3.创建监听列表
	listen(server,10);
	//准备一个接收客户端套接字的结构体
	addr_in_t client_addr={0};
	socklen_t client_len=sizeof(server_addr);
	//4.阻塞等待客户端请求
	int client=accept(server,(addr_t*)&client_addr,&client_len);
	printf("客户端连接成功:%d\n",client);
	//
	while(1)
	{
		char buf[128]={0};
		if(read(client,buf,128)==0)
		{
			printf("客户端度断开连接\n");
			close(client);
			close(server);
			break;
		}
		printf("%s\n",buf);
	}
	return 0;
}
